/**
 * 
 */
(function() {
	
	var sysUserTabGroupGrid = new HgUi.Datagrid("sysUserTabOrgView_grid");
	sysUserTabGroupGrid.grid = $("#sysUserTabOrgView_grid");
	sysUserTabGroupGrid.toolbar = $("#sysUserTabOrgView_toolbar");
	// sysUserTabGroupGrid.options.tipCells = ["sysGroup.groupName","sysGroup.descr","sysGroup.sysOrganization.orgName","sysGroup.groupCode","isLeader"];

	sysUserTabGroupGrid.init();
	function rowGroupCheckFunc(callback) {
		return function() {
			var row = sysUserTabGroupGrid.grid.datagrid("getSelected");
			if (!row){
				HgUi.alert("请选择一条小组数据");
				return;
			}
			callback(row);
		};
	}
	
	function rowUserCheckFunc(callback) {
		return function() {
			var row = sysUserGrid.grid.datagrid("getSelected");
			if (!row){
				HgUi.alert("请选择一条用户数据");
				return;
			}
			callback(row);
		};
	}
	
	/**
	 * 管理编辑
	 */
	sysUserTabGroupGrid.toolbar.find("a[tag='edit']").click(rowUserCheckFunc(function(row) {
		var rows = sysUserTabGroupGrid.grid.datagrid('getRows');
		HgUtil.chooseSysGroup(rows, function(groupIds) {
			var groupIdstr = groupIds.join(',');
			HgUtil.post("/sys/org/updateUserGroup", {
			    userId: row['userId'],
			    "groupIds": groupIdstr
			}, function() {
				sysUserTabGroupGrid.grid.datagrid("reload");
			});
		});
	}));
	
 
	
})();
